/*
 * Copyright (c) 2009, Katholieke Universiteit Leuven
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice,
 *       this list of conditions and the following disclaimer in the documentation
 *       and/or other materials provided with the distribution.
 *     * Neither the name of the Katholieke Universiteit Leuven nor the names of
 *       its contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * @addtogroup reconfiguration
 * @{
 */
/**
 * @defgroup runtime_control Runtime control
 * @{
 */
/**
 * @file 
 * Header file for the local runtime control functionality
 * @author 
 * Wouter Horré <wouter.horre@cs.kuleuven.be>
 */
#ifndef __LOOCI_RUNTIME_CONTROL_LOCAL_H__
#define __LOOCI_RUNTIME_CONTROL_LOCAL_H__

#include <stdbool.h>

#include "contiki.h"
#include "net/peers.h"
#include "events/eventtype.h"
#include "components/components.h"

/**
 * Deactivate a component
 *
 * @param cid The component identifier.
 *
 * @return 'true' if successful, 'false' in case of failure
 */
CCIF bool looci_rc_deactivate(u8_t cid);

/**
 * Activate a component
 *
 * @param cid The component identifier.
 *
 * @return 'true' if successful, 'false' in case of failure
 */
CCIF bool looci_rc_activate(u8_t cid);

/**
 * Remove all wirings for a component
 *
 * @param cid The component identifier
 *
 * @return 'true' if successful, 'false' in case of failure
 */
CCIF bool looci_rc_reset_wirings(u8_t cid);

/**
 * Wire a local component to another local component.
 *
 * @param type The event type
 * @param sid The component id of the event source
 * @param tid The component id of the event target
 *
 * @return 'true' if successful, 'false' in case of failure
 */
CCIF bool looci_rc_wire_local(looci_eventtype_t type, u8_t sid, u8_t tid);

/**
 * Wire a local component to a remote component on a given node
 * producing the given event type.
 *
 * @param type The event type
 * @param snode The source node of the events
 * @param sid The id of the (remote) source component
 * @param tid The id of the (local) target component
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_wire_remote_from(looci_eventtype_t type, peer_id_t snode, u8_t sid, u8_t tid);

/**
 * Wire a local component to all remote components on a given node 
 * that produce the given event type.
 *
 * @param type The event type
 * @param tid The id of the (local) target component
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_wire_remote_from_all(looci_eventtype_t type, u8_t tid); 

/**
 * Wire the events produced by a local component to a remote node.
 *
 * @param type The event type
 * @param sid The id of the (local) source component
 * @param tnode The target node
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_wire_remote_to(looci_eventtype_t type, u8_t sid, peer_id_t tnode);

/**
 * Wire the events produced by a local component to all nodes (broadcast).
 *
 * @param type The event type
 * @param sid The id of the (local) source component
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_wire_remote_to_all(looci_eventtype_t type, u8_t sid);

/**
 * Unwire a local component from another local component.
 *
 * @param type The event type
 * @param sid The component id of the event source
 * @param tid The component id of the event target
 *
 * @return 'True' if successful, 'false' otherwise
 */
CCIF bool looci_rc_unwire_local(looci_eventtype_t type, u8_t sid, u8_t tid);

/**
 * Unwire a local component from a remote component on a given node
 * producing the given event type.
 *
 * @param type The event type
 * @param snode The source node of the events
 * @param sid The id of the (remote) source component
 * @param tid The id of the (local) target component
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_unwire_remote_from(looci_eventtype_t type, peer_id_t snode, u8_t sid, u8_t tid);

/**
 * Unwire a local component from all remote components on a given node 
 * that produce the given event type.
 *
 * @param type The event type
 * @param tid The id of the (local) target component
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_unwire_remote_from_all(looci_eventtype_t type, u8_t tid); 

/**
 * Unwire a remote node from the events produced by a local component.
 *
 * @param type The event type
 * @param sid The id of the (local) source component
 * @param tnode The target node
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_unwire_remote_to(looci_eventtype_t type, u8_t sid, peer_id_t tnode);

/**
 * Unwire the broadcast address from the events produced by a local component.
 *
 * @param type The event type
 * @param sid The id of the (local) source component
 *
 * @return 'true' if successful, 'false' otherwise
 */
CCIF bool looci_rc_unwire_remote_to_all(looci_eventtype_t type, u8_t sid);

#endif // __LOOCI_RUNTIME_CONTROL_LOCAL_H__
/** @} */
/** @} */
